{{-- 模板名字 --}}
@extends('Layout/HomeBase')



{{-- 页面名字 --}}
@section('title', '商城主页')




{{-- 加载css文件 --}}
@section('css')
<link href="{{asset('Home/css/amazeui.css')}}" rel="stylesheet" type="text/css" />

<link href="{{asset('Home/css/demo.css')}}" rel="stylesheet" type="text/css" />
<link href="{{asset('Home/css/cartstyle.css')}}" rel="stylesheet" type="text/css" />

<link href="{{asset('Home/css/jsstyle.css')}}" rel="stylesheet" type="text/css" />


@endsection




{{-- 网页主体 --}}
@section('main')
@if (session('addr'))
	<script>
		alert("{{session('addr')}}")
	</script>
@endif
<div class="paycont">
  <div class="address">
    <h3>确认收货地址 </h3>
    <div class="control">
      <div class="tc-btn createAddr theme-login am-btn am-btn-danger">使用新地址</div>
    </div>
    <div class="clear"></div>
    @foreach($ress as $v)
    <ul>
      <div class="per-border"></div>
      <li class="user-addresslist defaultAddr">

        <div class="address-left">
          <div class="user DefaultAddr">

            <span class="buy-address-detail">
           <span class="buy-user">{{$v->linkman}}</span>
            <span class="buy-phone">{{$v->telephone}}</span>
            </span>
          </div>
          <div class="default-address DefaultAddr">
            <span class="buy-line-title buy-line-title-type">收货地址：</span>
            <span class="buy--address-detail">
           <span class="province">{{$v->province}}</span>
            <span class="city">{{$v->city}}</span>
            <span class="dist">{{$v->town}}</span>
            <span class="street">{{$v->dec}}</span>
            <span class="street">{{$v->id}} </span>
            </span>
            </span>
          </div>
        </div>
        <div class="address-right">
          <a href="../person/address.html">
            <span class="am-icon-angle-right am-icon-lg"></span></a>
        </div>
        <div class="clear"></div>
        <div class="new-addr-btn">
          <input type="radio" name="address" value="{{$v->id}}">选用
          <span class="new-addr-bar">|</span>
          <a href="{{url('/Home/deleteIntAddress')}}/{{$v->id}}" onclick="delClick(this);">删除</a>
        </div>
      </li>
      @endforeach
      <div class="per-border"></div>
    </ul>
    <div class="clear"></div>
  </div>
  <div class="clear"></div>

  <!--订单 -->
  <div class="concent">
    <div id="payTable">
      <h3>确认订单信息</h3>
      <div class="cart-table-th">
        <div class="wp">

          <div class="th th-item">
            <div class="td-inner">商品信息</div>
          </div>
          <div class="th th-price">
            <div class="td-inner">&nbsp;&nbsp;&nbsp;</div>
          </div>
          <div class="th th-amount">
            <div class="td-inner">数量</div>
          </div>
          <div class="th th-sum">
            <div class="td-inner">消耗积分</div>
          </div>

        </div>
      </div>
      <div class="clear"></div>

      <tr class="item-list">
        <div class="bundle  bundle-last">
          <div class="bundle-main">
            <ul class="item-content clearfix">
              <div class="pay-phone">
                <li class="td td-item">
                  <div class="item-pic">
                    <a href="#" class="J_MakePoint">
                      <img src="{{$goods->image}}" class="itempic J_ItemImg"></a>
                  </div>
                  <div class="item-info">
                    <div class="item-basic-info">
                      <a href="#" class="item-title J_MakePoint" data-point="tbcart.8.11">{{$goods->ig_name}}</a>
                    </div>
                  </div>
                </li>
                <li class="td td-info">
                  <div class="item-props">
                    <span class="sku-line">{{$goods->detail}}</span>
                    
                  </div>
                </li>
                <li class="td td-price">
                  <div class="item-price price-promo-promo">
                    <div class="price-content">
                      <em class="J_Price price-now"></em>
                    </div>
                  </div>
                </li>
              </div>
              <li class="td td-amount">
                <div class="amount-wrapper ">
                  <input type="hidden" name="goods_id" value="{{$goods->id}}">
                  <div class="item-amount ">
                    <span class="phone-title">购买数量</span>
                    <div class="sl">
                      
                      <span value="1" id='number'>1</span>
                      
                    </div>
                  </div>
                </div>
              </li>
              <li class="td td-sum">
                <div class="td-inner">
                  <em tabindex="0" class="J_ItemSum number">{{$goods->integral_price}}</em>
                </div>
              </li>

            </ul>
            <div class="clear"></div>

          </div>
      </tr>
      <div class="clear"></div>
      </div>
      </div>
      <div class="clear"></div>
      <div class="pay-total">
      
      <div class="clear"></div>
      </div>
      <div class="order-go clearfix">
        <div class="pay-confirm clearfix">
         
          <div id="holyshit269" class="submitOrder">
            <div class="go-btn-wrap">
              <a id="J_Go" href="javascript:;" class="btn-go" tabindex="0" title="点击此按钮，提交订单">提交订单</a>
            </div>
          </div>
          <div class="clear"></div>
        </div>
      </div>
    </div>

    <div class="clear"></div>
  </div>
</div>

</div>

<div class="theme-popover">
<!--标题 -->
<div class=" am-padding">
  <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add address</small></div>
</div>


<div class="am-u-md-12">
  <form class="am-form am-form-horizontal">

    <div class="am-form-group">
      <label for="user-name" class="am-form-label">收货人</label>
      <div class="am-form-content">
        <input type="text" id="user-name" name="linkman" placeholder="收货人">
      </div>
    </div>

    <div class="am-form-group">
      <label for="user-phone" class="am-form-label">手机号码</label>
      <div class="am-form-content">
        <input id="user-phone" placeholder="手机号必填" type="text" name="telephone">
      </div>
    </div>

    <div class="am-form-group">
      <label for="user-address" class="am-form-label">所在地</label>
		<div id="show">
			<div class="am-form-content address">
				<div class="form address" style="height: 27px;width:600px;padding-top: 5px;display: inline-block;">
					<select style="width:120px;" id="pro" name="pro">
						<option value="-1">--请选择省份--</option>
					</select>
					<select style="width:120px;" id="city" name="city">
						<option value="-1">--请选择城市--</option>
					</select>
					<select style="width:120px;" id="area" name="area">
						<option value="-1">--请选择区/县--</option>
					</select>
				</div>
			</div>
		</div>
    </div>

    <div class="am-form-group">
      <label for="user-intro" class="am-form-label">详细地址</label>
      <div class="am-form-content">
        <textarea class="" rows="3" id="user-intro" placeholder="输入详细地址" name="dec"></textarea>
        <small>100字以内写出你的详细地址...</small>
      </div>
    </div>

    <div class="am-form-group theme-poptit">
      <div class="am-u-sm-9 am-u-sm-push-3">
        <div class="am-btn am-btn-danger" id="preser">保存</div>
        <div class="am-btn am-btn-danger close">取消</div>
      </div>
    </div>
  </form>
</div>

</div>

<div class="clear"></div>




@endsection



{{-- 页脚JS代码 --}}
@section('bottom-js')
<script type="text/javascript" src="{{asset('Home/js/address.js')}}"></script>
<script>
   

  {{-- 城市三级联动 --}}

	$.post(
		"/shop/area",
		{'upid': '0', '_token': '{{ csrf_token() }}'},
		function (msg) {

			var str = '';
			for (var i=0; i < msg.data.length; i++) {
				str += '<option value="' + msg.data[i].id + '">' + msg.data[i].name + '</option>';
			}
			$('#pro').append(str);
		},
		'json'
	);


		$('div#show').on('change', 'select', function () {
			var that = $(this);
			if ($('#pro').val() < 0) {
				$('#city').empty();
				$('#city').append("<option value='-1'>--请选择城市--</option>");
				$('#area').empty();
				$('#area').append("<option value='-1'>--请选择区/县--</option>");
				return false;
			}
			if (that.attr('name') != "area") {
				that.next('select')[0].options.length = 0;
			}
				
			if ($('#city').val() < 0 ) {
				$('#area').empty();
				$('#area').append("<option value='-1'>--请选择区/县--</option>");
			}

			var currentId = $(this).val();

			// console.log(currentId);

			$.post(
				'/shop/area',
				{'upid': currentId, '_token': '{{ csrf_token() }}'},
				function (msg) {
					var str = '';
						// console.log(msg);
					for (var i = 0; i < msg.data.length; i++) {

						str += '<option value="'+msg.data[i].id+'">'+msg.data[i].name+'</option>';
					}
					if (that.attr('name') == 'pro') {
						that.next('select').append("<option value='-1'>--请选择城市--</option>");
					}
					that.next('select').append(str);
				},
				'json',
				
			);
			if (that.attr('name') == 'pro') {
				$('#area').empty();
				$('#area').append("<option value='-1'>--请选择区/县--</option>");
			}
		})
	
	{{-- 添加地址 --}}
	$('#preser').click(function () { 
		var linkman = $('input[name="linkman"]').val();
		var telephone = $('input[name="telephone"]').val();
		var pro = $('#pro option:selected').text();
		var city = $('#city option:selected').text();
		var area = $('#area option:selected').text();
		var dec = $('textarea[name="dec"]').val();
		var token  = "{{csrf_token()}}";
		//alert(dec);
		$.ajax({ 
				url: "{{url('/Home/appendAddress')}}",
				type: 'post',
				data: {'linkman':linkman, 'telephone':telephone, 'pro':pro, 'city':city, 'area':area, 'dec':dec, '_token':token},
				dataType: 'json',
				success:function (data) {
					console.log(data);
	                if (data.code == 2010) {
	                    alert(data.msg);
	                    location.href = "{{url('/Home/exchangeAddress')}}/{{$goods->id}}";
	                } else {
	                   
	                   alert(data.msg);

	                }     
	            },
	            error: function (errorText) {
	                var text = JSON.parse(errorText.responseText).errors;
	               
	                if (text) {
	                    for (var key in text) {
	                        alert(text[key][0]);
	                    }
	                } else {
	                        alert("未知错误");
	                }
	            }

			});
	});

	$('#J_Go').click(function () { 
		var addressId = $('input[name="address"]:checked').val();
		var token  = "{{csrf_token()}}";
		$.ajax({ 
				url: "{{url('/Home/submitIntegralOrder')}}",
				type: 'post',
				data: {'integral_goods_id':"{{$goods->id}}", 'addressId':addressId, 'integral_price':"{{$goods->integral_price}}", 'name':"{{$goods->ig_name}}", '_token':token},
				dataType: 'json',
				success:function (data) {
					//console.log(data);
	                if (data.code == 3010) {
	                    alert(data.msg);
	                    location.href = "{{url('/Home/integralGoods')}}";
	                } else {
	                   
	                   alert(data.msg);

	                }    
	            },
	            error: function (errorText) {
	                var text = JSON.parse(errorText.responseText).errors;
	               
	                if (text) {
	                    for (var key in text) {
	                        alert(text[key][0]);
	                    }
	                } else {
	                        alert("未知错误");
	                }
	            }

			});
		//alert(addressId);
	})

</script>

@endsection
